package mamikeji.liaowa.db;

import java.util.Collections;
import java.util.List;

import mamikeji.liaowa.application.MyApplication;
import mamikeji.liaowa.bean.PushMessage;
import mamikeji.liaowa.gen.PushMessageDao;

/**
 * Created by Administrator on 2017/8/2 0002.
 */
public class PushMessageManager {
    public static long insert(PushMessage pushMessage) {
        return MyApplication.getInstance().getDaoSession().insert(pushMessage);
    }

    public static void delete(PushMessage pushMessage) {
        MyApplication.getInstance().getDaoSession().delete(pushMessage);
    }

    public static void deleteAll() {
        MyApplication.getInstance().getDaoSession().deleteAll(PushMessage.class);
    }

    public static void update(PushMessage pushMessage) {
        MyApplication.getInstance().getDaoSession().update(pushMessage);
    }

    public static PushMessage query(long id) {
        return MyApplication.getInstance().getDaoSession().load(PushMessage.class, id);
    }

    public static int getUnReadMessage() {
        List<PushMessage> pushMessageList = MyApplication.getInstance().getDaoSession().queryBuilder(PushMessage.class).where(PushMessageDao.Properties.IsRead.eq("false")).list();
        if (!pushMessageList.isEmpty()) {
            return pushMessageList.size();
        } else {
            return 0;
        }
    }

    public static List<PushMessage> queryAll() {
        List<PushMessage> pushMessagesList = MyApplication.getInstance().getDaoSession().loadAll(PushMessage.class);
        if (!pushMessagesList.isEmpty()) {
            return pushMessagesList;
        } else {
            return Collections.emptyList();
        }
    }
}
